#include <stdio.h>
#include <inttypes.h>

// 10^9是111011100110101100101000000000，共30位
#define MAX_BIT 29
typedef int64_t num_t;
#define num_ph SCNd64

#define MAX(a, b) ((a) > (b) ? (a) : (b))

int main(void) {
    int t;
    scanf("%d", &t);
    for(int i = 0; i < t; i++) {
        num_t num;
        scanf("%" num_ph, &num);
        int len = -1;
        int ones = 0;
        for (int bit = MAX_BIT; bit >= 0; bit--) {
            num_t base = ((num_t) 1) << bit;
            num_t digit = num & base;
            if (digit != 0) {
                if (len == -1) {
                    len = bit + 1;
                }
                ones++;
            }
        }
        printf("%d\n", len != -1 ? MAX(2 * ones - len, 0) : 0);
    }
    return 0;
}
